<template>
	<section>

		<el-col :span="24" class="toolbar"  style="padding-bottom: 0px;">
			<el-form :inline="true">
				<el-form-item>
					<el-button type="primary" @click="handleAdd">添加课程小节</el-button>
				</el-form-item>				
				<el-form-item>
					<el-input v-model="key"  placeholder="输入查询的关键字"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="getList">查询</el-button>
				</el-form-item>
			</el-form>
		</el-col>			
		<!--列表-->

		<el-tabs v-model="isShared"  type="card">
		    <el-tab-pane label="我的课程小节" name=' '></el-tab-pane>
		    <el-tab-pane label="共享课程小节" name='1'></el-tab-pane>
		    <el-tab-pane label="内置课程小节" name='2'></el-tab-pane>
		</el-tabs>	
		<!--工具条-->		
		<el-table :data="Lists" highlight-current-row v-loading="loading" style="width: 100%;" @sort-change="sortChange">
			<el-table-column  type="index"   width='80'>
			</el-table-column>
			<el-table-column prop="name" label="课程小节名称"width="200">
			</el-table-column>
			<el-table-column prop="realName" label="创建人" width="200" >
			</el-table-column>
			<el-table-column prop="orgName" label="所属单位" width="200">
			</el-table-column>			
			<el-table-column prop="createTime" label="添加时间" width="200">
			</el-table-column>
			<el-table-column prop="referenceCount" label="引用次数" width="200">
			</el-table-column>			
			<el-table-column prop="birth" min-width="200" label="操作" fixed="right" >
				<template scope="scope">
					<el-button size="small"  v-if="isShared==' '||$store.state.role=='admin'" type="danger" @click="handleDel(scope.row)">删除</el-button>
					<el-button size="small"  v-if="isShared==' '||$store.state.role=='admin'" type="primary" @click="getone(scope.row,'edit')">编辑</el-button>
					<el-button size="small" type="success" @click="getone(scope.row,'look')">查看</el-button>
					<el-button size="small" type="warning" v-if="scope.row.isShared==false&&isShared!=2&&$store.state.role!='admin'" @click="goShared(scope.row,1)">共享</el-button>
					<el-button size="small" type="info" v-if="scope.row.isShared==true&&isShared!=2">已共享</el-button>
				</template>					
			</el-table-column>
		</el-table>
		<!--工具-->
		<el-col :span="24" class="toolbar">
			<el-pagination layout="prev, pager, next" @current-change="handleCurrentChange" :page-size="10" :total="total" style="float:right;">
			</el-pagination>
		</el-col>		
		<!--新增界面-->
		<el-dialog  title="添加课程小节" :fullscreen="false" custom-class="templetdialog" width="30%"  v-model="addFormVisible" :close-on-click-modal="false">
			<el-form :model="addtemplet" status-icon class="demo-ruleForm" :rules="addtempletrule" ref="addtemplet" label-width="50px">		
				<el-form-item label="课程小节名称"  label-width="80"  prop="name"> 
				    <el-input style="width:40%;" type="text" placeholder="填写小节名称（15字以内）"  v-model="addtemplet.name"></el-input>
				</el-form-item>	
				<el-form-item label="课程小节类型" label-width="80" prop="courseStage">
				    <el-radio-group v-model="addtemplet.courseStage">
				      <el-radio label="0">创业基础课程小节</el-radio>
				      <el-radio label="1">案例分析课程小节</el-radio>
				    </el-radio-group>
				</el-form-item>	
				<el-form-item label="所属商业模式版块儿" label-width="80"  prop="businessModelId" v-if="addtemplet.courseStage==0">
				    <el-select placeholder="请选择版块儿"  v-model="addtemplet.businessModelId">
				      <el-option v-for="el in bussinessList" :value="el.businessModelId" :label="el.name"></el-option>
				    </el-select>
				</el-form-item>				
				<el-form-item label="教案选择"  label-width="80" >
					<el-row>
						<el-col :span="6">
						    <el-select placeholder="请选择教案选择" style="width: 100%;" v-model="addtemplet.planIds" multiple >
						      <el-option v-for="el in planlist" :value="el.planId" :label="el.name"></el-option>
						    </el-select>							
						</el-col>
						<el-col :span="12" :offset="2">
						  <el-radio-group v-model="planselect">
						    <el-radio-button label="1">只看自己</el-radio-button>
						    <el-radio-button label="2">共享教案</el-radio-button>
						    <el-radio-button label="3">内置教案</el-radio-button>
						  </el-radio-group>							
						</el-col>						
					</el-row>

				</el-form-item>				
				<el-form-item label="视频选择" label-width="80">
					<el-row>
						<el-col :span="6">
						    <el-select placeholder="请选择视频选择" style="width: 100%;" v-model="addtemplet.videoIds" multiple >
						      <el-option v-for="el in videolist" :value="el.videoId" :label="el.name"></el-option>
						    </el-select>							
						</el-col>
						<el-col :span="12" :offset="2">
							<el-radio-group v-model="videoselect">
							    <el-radio-button label="1">只看自己</el-radio-button>
							    <el-radio-button label="2">共享视频</el-radio-button>
							    <el-radio-button label="3">内置视频</el-radio-button>
							</el-radio-group>							
						</el-col>							
					</el-row>
				</el-form-item>		
				<el-form-item label="图纸选择" label-width="80">
					<el-row>
						<el-col :span="6">
						    <el-select placeholder="请选择教案选择" style="width: 100%;" v-model="addtemplet.drawingIds" multiple >
						      <el-option v-for="el in drawlist" :value="el.drawingId" :label="el.name"></el-option>
						    </el-select>							
						</el-col>
						<el-col :span="12" :offset="2">
							<el-radio-group v-model="drawselect">
							    <el-radio-button label="1">只看自己</el-radio-button>
							    <el-radio-button label="2">共享图纸</el-radio-button>
							    <el-radio-button label="3">内置图纸</el-radio-button>
							</el-radio-group>							
						</el-col>							
					</el-row>
				</el-form-item>		
				<el-form-item label="作业选择" label-width="80">
					<el-row>
						<el-col  :span="6">
						    <el-select placeholder="请选择作业选择" style="width: 100%;" v-model="addtemplet.problemIds" multiple >
						      <el-option v-for="el in worklist" :value="el.problemId" :label="el.name"></el-option>
						    </el-select>							
						</el-col>
						<el-col :span="12" :offset="2">
							<el-radio-group v-model="workselect">
							    <el-radio-button label="1">只看自己</el-radio-button>
							    <el-radio-button label="2">共享作业</el-radio-button>
							    <el-radio-button label="3">内置作业</el-radio-button>
							</el-radio-group>							
						</el-col>
					</el-row>
				</el-form-item>							
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click.native="addFormVisible = false">取消</el-button>
				<el-button type="primary" @click.native="addSubmit" :loading="addLoading">提交</el-button>
			</div>
		</el-dialog>
		<!--编辑界面-->
		<el-dialog  title="编辑课程小节" :fullscreen="false" custom-class="templetdialog" width="30%"  v-model="editFormVisible" :close-on-click-modal="false">
			<el-form :model="edittemplet" status-icon class="demo-ruleForm" :rules="edittempletrule" ref="edittemplet" label-width="50px">		
				<el-form-item label="课程小节名称"  label-width="80"  prop="name"> 
				    <el-input style="width:40%;" type="text"  placeholder="填写小节名称（15字以内）"  v-model="edittemplet.name"></el-input>
				</el-form-item>	
				<el-form-item label="课程小节类型" label-width="80" prop="courseStage" >
				    <el-radio-group v-model="edittemplet.courseStage" disabled>
				      <el-radio label="0">创业基础课程小节</el-radio>
				      <el-radio label="1">案例分析课程小节</el-radio>
				    </el-radio-group>
				</el-form-item>	
				<el-form-item label="所属商业模式版块儿" label-width="80"  prop="businessModelId" v-if="edittemplet.courseStage==0">
				    <el-select placeholder="请选择版块儿"  v-model="edittemplet.businessModelId">
				      <el-option v-for="el in bussinessList" :value="el.businessModelId" :label="el.name"></el-option>
				    </el-select>
				</el-form-item>				
				<el-form-item label="教案选择"  label-width="80" >
					<el-row>
						<el-col :span="6">
						    <el-select placeholder="请选择教案选择" style="width: 100%;" v-model="edittemplet.planIds" multiple >
						      <el-option v-for="el in planlist" :value="el.planId" :label="el.name"></el-option>
						    </el-select>							
						</el-col>
						<el-col :span="12" :offset="2">
						  <el-radio-group v-model="planselect">
						    <el-radio-button label="1">只看自己</el-radio-button>
						    <el-radio-button label="2">共享教案</el-radio-button>
						    <el-radio-button label="3">内置教案</el-radio-button>
						  </el-radio-group>							
						</el-col>						
					</el-row>

				</el-form-item>				
				<el-form-item label="视频选择" label-width="80">
					<el-row>
						<el-col :span="6">
						    <el-select placeholder="请选择视频选择" style="width: 100%;" v-model="edittemplet.videoIds" multiple >
						      <el-option v-for="el in videolist" :key="el.videoId" :value="el.videoId" :label="el.name"></el-option>
						    </el-select>							
						</el-col>
						<el-col :span="12" :offset="2">
							<el-radio-group v-model="videoselect">
							    <el-radio-button label="1">只看自己</el-radio-button>
							    <el-radio-button label="2">共享视频</el-radio-button>
							    <el-radio-button label="3">内置视频</el-radio-button>
							</el-radio-group>							
						</el-col>							
					</el-row>
				</el-form-item>		
				<el-form-item label="图纸选择" label-width="80">
					<el-row>
						<el-col :span="6">
						    <el-select placeholder="请选择教案选择" style="width: 100%;" v-model="edittemplet.drawingIds" multiple >
						      <el-option v-for="el in drawlist" :value="el.drawingId" :label="el.name"></el-option>
						    </el-select>							
						</el-col>
						<el-col :span="12" :offset="2">
							<el-radio-group v-model="drawselect">
							    <el-radio-button label="1">只看自己</el-radio-button>
							    <el-radio-button label="2">共享图纸</el-radio-button>
							    <el-radio-button label="3">内置图纸</el-radio-button>
							</el-radio-group>							
						</el-col>							
					</el-row>
				</el-form-item>		
				<el-form-item label="作业选择" label-width="80">
					<el-row>
						<el-col  :span="6">
						    <el-select placeholder="请选择作业选择" style="width: 100%;" v-model="edittemplet.problemIds" multiple >
						      <el-option v-for="el in worklist" :value="el.problemId" :label="el.name"></el-option>
						    </el-select>							
						</el-col>
						<el-col :span="12" :offset="2">
							<el-radio-group v-model="workselect">
							    <el-radio-button label="1">只看自己</el-radio-button>
							    <el-radio-button label="2">共享作业</el-radio-button>
							    <el-radio-button label="3">内置作业</el-radio-button>
							</el-radio-group>							
						</el-col>
					</el-row>
				</el-form-item>							
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click.native="editFormVisible = false">取消</el-button>
				<el-button type="primary" @click.native="editSubmit" :loading="editLoading">更新</el-button>
			</div>
		</el-dialog>	
		<!--查看界面-->
		<el-dialog  title="查看课程小节" :fullscreen="false" custom-class="templetdialog" width="30%"  v-model="lookVisible" :close-on-click-modal="false">
			<el-form :model="edittemplet" status-icon class="demo-ruleForm" :rules="edittempletrule" ref="edittemplet" label-width="50px">		
				<el-form-item label="课程小节名称"  label-width="80" > 
				    <el-input style="width:40%;" type="text"  v-model="edittemplet.name" disabled ></el-input>
				</el-form-item>	
				<el-form-item label="课程小节类型" label-width="80" >
				    <el-radio-group v-model="edittemplet.courseStage" disabled >
				      <el-radio label="0">创业基础课程小节</el-radio>
				      <el-radio label="1">案例分析课程小节</el-radio>
				    </el-radio-group>
				</el-form-item>	
				<el-form-item label="所属商业模式版块儿" label-width="80"  v-if="edittemplet.courseStage==0">
				    <el-select placeholder="请选择版块儿"  v-model="edittemplet.businessModelId" disabled >
				      <el-option v-for="el in bussinessList" :value="el.businessModelId" :label="el.name"></el-option>
				    </el-select>
				</el-form-item>				
				<el-form-item label="教案选择"  label-width="80" >
					<el-row>
						<el-col :span="6">
						    <el-select placeholder="请选择教案选择" style="width: 100%;" v-model="edittemplet.planIds" multiple disabled >
						      <el-option v-for="el in planlist" :value="el.planId" :label="el.name"></el-option>
						    </el-select>							
						</el-col>						
					</el-row>

				</el-form-item>				
				<el-form-item label="视频选择" label-width="80">
					<el-row>
						<el-col :span="6">
						    <el-select placeholder="请选择视频选择" style="width: 100%;" v-model="edittemplet.videoIds" multiple disabled  >
						      <el-option v-for="el in videolist" :key="el.videoId" :value="el.videoId" :label="el.name"></el-option>
						    </el-select>							
						</el-col>						
					</el-row>
				</el-form-item>		
				<el-form-item label="图纸选择" label-width="80">
					<el-row>
						<el-col :span="6">
						    <el-select placeholder="请选择教案选择" style="width: 100%;" v-model="edittemplet.drawingIds" multiple disabled >
						      <el-option v-for="el in drawlist" :value="el.drawingId" :label="el.name"></el-option>
						    </el-select>							
						</el-col>							
					</el-row>
				</el-form-item>		
				<el-form-item label="作业选择" label-width="80">
					<el-row>
						<el-col  :span="6">
						    <el-select placeholder="请选择作业选择" style="width: 100%;" v-model="edittemplet.problemIds" multiple disabled >
						      <el-option v-for="el in worklist" :value="el.problemId" :label="el.name"></el-option>
						    </el-select>							
						</el-col>
					</el-row>
				</el-form-item>							
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click.native="lookVisible = false">关闭</el-button>
			</div>
		</el-dialog>			
	</section>
</template>
<script>
	import {videolistbuil,worklistbuil,drawlistbuil,planlistbuil, templetlist,templetdelete,templetadd,templetone,templetedit,bussinesslist,templetlistbuil,templetnamerule,videolist,worklist,drawlist,planlist} from '../../api/api';

	export default {	
		data() {
			var rulesname=(rules,value,callback)=>{
				let params={name:this.addtemplet.name};
				templetnamerule(params).then((r)=>{
					if(!r){
						callback(new Error('作业名称重复'))
					}else{
						callback()
					}
				})
			}	
			var editrulesname=(rules,value,callback)=>{
				if(this.edittemplet.checkname!=this.edittemplet.name){			
					let params={name:this.edittemplet.name};
					templetnamerule(params).then((r)=>{
						if(!r){
							callback(new Error('作业名称重复'))
						}else{
							callback()
						}
					})
				}else{
					callback()
				}
			}				
			let numberrule=(rule, value, callback)=>{
			  if (value < 0 || value > 10) {
			    callback(new Error('分值必须在 0 至 10之间'))
			  } else {
			    callback()
			  }							
			}
			let namelengthrule=(rule, value, callback)=>{
			  if (value.length > 15) {
			    callback(new Error('限制字数15字以内'))
			  } else {
			    callback()
			  }							
			}			
			return {
				planselect:"1",
				videoselect:"1",
				drawselect:"1",
				workselect:"1",
				planisShared:" ",				
				videoisShared:" ",	
				drawisShared:" ",	
				workisShared:" ",	
				planisSelf:"1",
				videoisSelf:"1",
				drawisSelf:"1",
				workisSelf:"1",
				Type:"",
				addFormVisible: false,
				addLoading: false,	
				autotemplet:false,
				editFormVisible: false,
				editLoading: false,						
				loading: true,
				lookVisible:false,
				templetupload:"templet",
				Lists:[],
				fileList:[],
				checkbox:[],
				editfileList:[],	
				bussinessList:[],
				addtemplet:{
					name:"",
					type:"",
					courseStage:"",
					businessModelId:"",
					planIds:[],
					problemIds:[],
					videoIds:[],
					drawingIds:[],
				},
				edittemplet:{
					planIds:[],
					problemIds:[],
					videoIds:[1,2],
					drawingIds:[],
				},					
				addtempletrule: {
					name: [
						{ required: true, message: '请填写课程小节名称', trigger: 'blur' },
						{validator:rulesname,trigger: 'blur'},
					],
					courseStage:[
						{ required: true, message: '请选择课程小节类别', trigger: 'blur' }
					],
					score:[
						{required: true, validator:numberrule, trigger: 'blur'}
					],
					businessModelId:[
						{ required: true, message: '请选择所属商业模式版块儿', trigger: 'blur' }
					]					
				},	
				edittempletrule: {
					name: [
						{ required: true, message: '请填写课程小节名称', trigger: 'blur' },
						{validator:editrulesname,trigger: 'blur'},
						{validator:namelengthrule,trigger: 'blur'}
						
					],
					courseStage:[
						{ required: true, message: '请选择课程小节类别', trigger: 'blur' }
					],
					score:[
						{required: true, validator:numberrule, trigger: 'blur'}
					],
					businessModelId:[
						{ required: true, message: '请选择所属商业模式版块儿', trigger: 'blur' }
					]	
				},
				param:"",
				eidtparam:"",	
				page:"1",
				pagesize:"10",
				total:'',
				key:"",
				isShared:" ",
				isSelf:"1",
				videolist:[],
				worklist:[],
				drawlist:[],
				planlist:[],
				templettype:"",
			}
		},
		watch:{
			'isShared':function(){
				this.getList()
			},
			'addtemplet.courseStage':function(){
				this.planselect=1;
				this.videoselect=1;
				this.drawselect=1;
				this.workselect=1;				
				this.getvideoList(1);
				this.getworkList(1);
				this.getdrawList(1);
				this.getplanList(1);				
			},
			'addtemplet.businessModelId':function(){
				this.planselect=1;
				this.videoselect=1;
				this.drawselect=1;
				this.workselect=1;		
				this.getvideoList(1);
				this.getworkList(1);
				this.getdrawList(1);
				this.getplanList(1);				
			},
			'edittemplet.courseStage':function(){
				this.planselect=1;
				this.videoselect=1;
				this.drawselect=1;
				this.workselect=1;				
				this.getvideoList(1);
				this.getworkList(1);
				this.getdrawList(1);
				this.getplanList(1);				
			},
			'edittemplet.businessModelId':function(){
				this.planselect=1;
				this.videoselect=1;
				this.drawselect=1;
				this.workselect=1;		
				this.getvideoList(1);
				this.getworkList(1);
				this.getdrawList(1);
				this.getplanList(1);				
			},			
			'planselect':function(){
				if(this.planselect==1){
					this.planisShared=' ';
					this.planisSelf=1;
					this.getplanList(1);							
				}
				if(this.planselect==2){
					this.planisShared='1';
					this.planisSelf='0';
					this.getplanList(1);							
				}
				if(this.planselect==3){
					this.getplanList();							
				}				
			},
			'videoselect':function(){
				if(this.videoselect==1){
					this.videoisSelf=1;
					this.videoisShared=' ';
					this.getvideoList(1);							
				}
				if(this.videoselect==2){
					this.videoisShared='1';
					this.videoisSelf='0';
					this.getvideoList(1);							
				}
				if(this.videoselect==3){
					this.getvideoList();							
				}				
			},
			'workselect':function(){
				if(this.workselect==1){
					this.workisSelf=1;
					this.workisShared=' ';
					this.getworkList(1);							
				}
				if(this.workselect==2){
					this.workisShared='1';
					this.workisSelf='0';					
					this.getworkList(1);							
				}
				if(this.workselect==3){
					this.getworkList();							
				}				
			},
			'drawselect':function(){
				if(this.drawselect==1){
					this.drawisSelf=1;
					this.drawisShared=' ';
					this.getdrawList(1);							
				}
				if(this.videoselect==2){
					this.drawisShared='1';
					this.drawisSelf='0';	
					this.getdrawList(1);							
				}
				if(this.videoselect==3){
					this.getdrawList();							
				}				
			}			
		},
		methods: {	
		    sortChange:function(column, prop, order){
				if(column){
			      var type='';
			      if(column.prop=='createTime'){
			      	column.prop='create_time';
			      }else if(column.prop=='referenceCount'){
			      	column.prop='reference_count';
			      }
			      if(column.order=="ascending"){
			      	type=column.prop;	
			      }else if(column.order=='descending'){
			      	type=column.prop+' '+'desc';
			      }
			      this.getList(type)			 	
				}
		    },				
			getvideoList: function (type) {
				if(this.templettype=='edit'){
					var courseStage=this.edittemplet.courseStage;
					var businessModelId=this.edittemplet.businessModelId
				}else{
					var courseStage=this.addtemplet.courseStage;
					var businessModelId=this.addtemplet.businessModelId					
				}
				if(type){
					let params={pageNum:'1',pageSize:200,isSelf:this.videoisSelf,isShared:this.videoisShared,courseStage:courseStage,businessModelId:businessModelId};
					videolist(params).then((res) => {
						$.each(res.list, function(e,value) {
							value.videoId=JSON.stringify(value.videoId)
						});
						this.videolist = res.list;
					});					
				}else{
					let params={pageNum:'1',pageSize:200,courseStage:courseStage,businessModelId:businessModelId};
					videolistbuil(params).then((res) => {
						$.each(res.list, function(e,value) {
							value.problemId=JSON.stringify(value.problemId)						
						});
						this.videolist = res.list;
					});					
				}
			},
			getworkList: function (type) {
				if(this.templettype=='edit'){
					var courseStage=this.edittemplet.courseStage;
					var businessModelId=this.edittemplet.businessModelId
				}else{
					var courseStage=this.addtemplet.courseStage;
					var businessModelId=this.addtemplet.businessModelId					
				}			
				if(type){
					let params={pageNum:'1',pageSize:200,isSelf:this.workisSelf,isShared:this.workisShared,courseStage:courseStage,businessModelId:businessModelId};
					worklist(params).then((res) => {
						$.each(res.list, function(e,value) {
							value.problemId=JSON.stringify(value.problemId)						
						});						
						this.worklist = res.list;
					});					
				}else{
					let params={pageNum:'1',pageSize:200,courseStage:courseStage,businessModelId:businessModelId};
					worklistbuil(params).then((res) => {
						$.each(res.list, function(e,value) {
							value.problemId=JSON.stringify(value.problemId)						
						});						
						this.worklist = res.list;
					});					
				}
			},		
			getdrawList: function (type) {
				if(this.templettype=='edit'){
					var courseStage=this.edittemplet.courseStage;
					var businessModelId=this.edittemplet.businessModelId
				}else{
					var courseStage=this.addtemplet.courseStage;
					var businessModelId=this.addtemplet.businessModelId					
				}					
				if(type){
					let params={pageNum:'1',pageSize:200,isSelf:this.drawisSelf,isShared:this.drawisShared,courseStage:courseStage,businessModelId:businessModelId};
					drawlist(params).then((res) => {
						$.each(res.list, function(e,value) {
							value.drawingId=JSON.stringify(value.drawingId)						
						});						
						this.drawlist = res.list;
					});					
				}else{
					let params={pageNum:'1',pageSize:200,courseStage:courseStage,businessModelId:businessModelId};
					drawlistbuil(params).then((res) => {
						$.each(res.list, function(e,value) {
							value.drawingId=JSON.stringify(value.drawingId)						
						});							
						this.drawlist = res.list;
					});					
				}
			},	
			getplanList: function (type) {
				if(this.templettype=='edit'){
					var courseStage=this.edittemplet.courseStage;
					var businessModelId=this.edittemplet.businessModelId
				}else{
					var courseStage=this.addtemplet.courseStage;
					var businessModelId=this.addtemplet.businessModelId					
				}					
				if(type){
					let params={pageNum:'1',pageSize:200,isSelf:this.planisSelf,isShared:this.planisShared,courseStage:courseStage,businessModelId:businessModelId};
					planlist(params).then((res) => {
						$.each(res.list, function(e,value) {
							value.planId=JSON.stringify(value.planId)						
						});							
						this.planlist = res.list;
					});					
				}else{
					let params={pageNum:'1',pageSize:200,courseStage:courseStage,businessModelId:businessModelId};
					planlistbuil(params).then((res) => {
						$.each(res.list, function(e,value) {
							value.planId=JSON.stringify(value.planId)						
						});							
						this.planlist = res.list;
					});					
				}
			},					    
			goShared:function(row,type){
				this.$confirm('确定共享资源吗?', '提示', {
			        confirmButtonText: '确定',
			        cancelButtonText: '取消',					
					type: 'warning'
				}).then(() => {
					var params=new URLSearchParams();
					params.append('isShared',type);
					params.append('templetId',row.templetId);
					templetedit(params).then((r) => {
						if(!r.error){
							this.$message({
								message: '共享成功',
								type: 'success'
							});
							this.getList();									
						}else{
							this.$message({
								message: '共享失败',
								type: 'error'
							});						
						}
					})	
				}).catch(() => {
					this.$message({
						type: 'info',
						message: '取消共享'		
					});						
				});				
			
			},
			handleAdd: function () {
				this.addFormVisible = true;
			},
			isSharedclick:function(type){
				this.isShared=type;
				this.getList();
			},
			//获取商业模式列表
			getbussinesslist:function(){
				bussinesslist().then((res)=>{
					$.each(res, function(i,value) {
						value.businessModelId=JSON.stringify(value.businessModelId)
					});
					this.bussinessList=res;
				})
			},	
			//获取项目列表
			getList: function (type) {
				this.loading = true;
				//NProgress.start();
				if(this.isShared!=2){
					let params={pageNum:this.page,pageSize:this.pagesize,key:this.key,isShared:this.isShared,isSelf:this.isSelf,orderByClause:type};
					templetlist(params).then((res) => {
						this.total=res.total;		
						this.Lists = res.list;
						this.loading = false;
					});					
				}else{
					let params={pageNum:this.page,pageSize:this.pagesize,key:this.key,orderByClause:type};
					templetlistbuil(params).then((res) => {
						this.total=res.total;					
						this.Lists = res.list;
						this.loading = false;
					});					
				}
			},
			getone:function(row,type){
				var params=row.templetId;
				this.templettype='edit';
				templetone(params).then((res)=>{
					 var _this = this
					 _this.edittemplet={};
					if(!res.error){
						if(res.drawingIds!=null){
							res.drawingIds=res.drawingIds.split(',')
						}else{
							res.drawingIds=[]
						}
						if(res.problemIds!=null){
							res.problemIds=res.problemIds.split(',')
						}else{
							res.problemIds=[]
						}
						if(res.planIds!=null){
							res.planIds=res.planIds.split(',')
						}else{
							res.planIds=[]
						}	
						if(res.videoIds!=null){
							res.videoIds=res.videoIds.split(',')
						}else{
							res.videoIds=[]
						}		
						res.checkname=res.name;
						res.courseStage=JSON.stringify(res.courseStage);				
						res.businessModelId=JSON.stringify(res.businessModelId);						
						_this.edittemplet = Object.assign({}, res);

						console.log(this.edittemplet.videoIds)
						if(type=='edit'){
							_this.editFormVisible=true;
						}else{
							_this.lookVisible=true;
						}	

					}
				})
			},
			handleCurrentChange(val) {
				this.page = val;
				this.getList();
			},		            
			handleDel:function (row) {
				this.$confirm('确认删除该记录吗?', '提示', {
			        confirmButtonText: '确定',
			        cancelButtonText: '取消',					
					type: 'warning'
				}).then(() => {
					this.listLoading = true;
					//NProgress.start();
					let para =row.templetId;
					
					templetdelete(para).then((res) => {
						if(!res.error){
							this.listLoading = false;
							//NProgress.done();
							this.$message({
								message: '删除成功',
								type: 'success'
							});
							this.getList();							
						}
					});
				}).catch(() => {
					this.$message({
						type: 'info',
						message: '取消删除'		
					});						
				});
			},
			//新增
			addSubmit: function () {			
				this.param=new URLSearchParams();
				this.$refs.addtemplet.validate((valid) => {
					if (valid) {
						this.$confirm('确认提交吗？', '提示', {}).then(() => {
							this.addLoading = true;
							this.param.append('name',this.addtemplet.name);
							this.param.append('videoIds',this.addtemplet.videoIds);				
							this.param.append('problemIds',this.addtemplet.problemIds);
							this.param.append('drawingIds',this.addtemplet.drawingIds);
							this.param.append('planIds',this.addtemplet.planIds);
							this.param.append('courseStage',this.addtemplet.courseStage);
							if(this.addtemplet.courseStage==0){
								this.param.append('businessModelId',this.addtemplet.businessModelId);
							}
							templetadd(this.param).then((r) => {
								if(!r.error){
									this.addLoading = false;
									this.$message({
										message: '添加成功',
										type: 'success'
									});
									this.$refs['addtemplet'].resetFields();
									this.addFormVisible = false;
									this.param='';
									this.getList();									
								}else{
									this.addLoading = false;
									this.param='';
									this.$message({
										message: '添加失败',
										type: 'error'
									});										
								}
							}).catch(()=>{
								this.addLoading = false;
								this.param='';
								this.$message({
									message: '添加失败',
									type: 'error'
								});								
							});
						});
					}
				});
			},
			//编辑
			editSubmit: function () {
				this.editparam=new URLSearchParams();	
				this.$refs.edittemplet.validate((valid) => {
					if (valid) {
						this.$confirm('确认提交吗？', '提示', {}).then(() => {
							this.editLoading = true;
							//NProgress.start();
							this.editparam.append('name',this.edittemplet.name);
							this.editparam.append('videoIds',this.edittemplet.videoIds);
							this.editparam.append('problemIds',this.edittemplet.problemIds);
							this.editparam.append('drawingIds',this.edittemplet.drawingIds);
							this.editparam.append('planIds',this.edittemplet.planIds);
							this.editparam.append('templetId',this.edittemplet.templetId);
							this.editparam.append('courseStage',this.edittemplet.courseStage);
							if(this.editparam.courseStage==0){
								this.editparam.append('businessModelId',this.addtemplet.businessModelId);
							}
							templetedit(this.editparam).then((r) => {
								if(!r.error){
									this.editLoading = false;
									this.$message({
										message: '更新成功',
										type: 'success'
									});
									this.$refs['edittemplet'].resetFields();
									this.editFormVisible = false;
									this.eidtparam='',
									this.getList();									
								}else{
								    this.editLoading = false;
									this.eidtparam='',
									this.$message({
										message: '更新失败',
										type: 'error'
									});											
								}
							}).catch(()=>{
								this.editLoading = false;
								this.eidtparam='',
								this.$message({
									message: '更新失败',
									type: 'error'
								});								
							});
						});
					}
				});
			},			
		},
		mounted() {
			this.getvideoList(1);
			this.getworkList(1);
			this.getdrawList(1);
			this.getplanList(1);
			this.getList()
			this.getbussinesslist()
		}
	};

</script>

<style>

.templetauto{
	display: none;
}
</style>